﻿@model  Authentication.Model.ViewModel.Warranty.PeriodInquiryViewModel
<ul class="breadcrumb">
    <li>
        <i class="icon-home"></i>
        <a href="/">Customer</a>
        <i class="icon-angle-right"></i>
    </li>
    <li>
        <i class="icon-file"></i>
        <a href="#">Period Inquiry</a>
    </li>
</ul>
<!--/span-->
<div class="row-fluid">
    <div class="box span12 orange">
        <div class="box-header" data-original-title>
            <h2><i class="halflings-icon search white"></i><span class="break"></span>Search infomation</h2>
        </div>
        <div class="box-content">
            <div class="row-fluid">
                <div class="span3">
                    <div class="desc">
                        <div class="title">Serial</div>
                        <div>
                            @Html.TextBoxFor(m => m.SerialNumber, new { @class = "span12" })
                        </div>
                    </div>
                </div>
                <div class="span2">
                    <div class="desc">
                        <div class="title">Model</div>
                        <div>
                            @Html.TextBoxFor(m => m.Model, new { @class = "span12" })
                        </div>
                    </div>
                </div>
                <div class="span7">
                    <div class="button-panel">
                        @Html.HiddenFor(x => x.Otp)
                        @Html.HiddenFor(x => x.OtpCounter)
                        <button id="btnSearch" type="submit" class="btn btn-success btn-responsive"><i class="icon-search"></i>&nbsp;Search</button>
                        <button id="btnImport" type="submit" class="btn btn-success btn-responsive" disabled="disabled"><i class="icon-download-alt"></i>&nbsp;Export data</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--/row-->
<div class="row-fluid">
    <div class="box span12">
        <div class="box-header" data-original-title>
            <h2><i class="halflings-icon th-large"></i><span class="break"></span>Period Inquiry</h2>
            <div class="box-icon">
                <a href="#" class="btn-minimize"><i class="halflings-icon chevron-up"></i></a>
            </div>
        </div>
        <div class="box-content">
            <table class="table table-striped bootstrap-datatable datatable" id="dataTables-1">
                <thead>
                    <tr>
                        <th class="text-left all">SerialNumber</th>
                        <th class="text-left">BoxNo</th>
                        <th class="text-left">ProductModel</th>
                        <th class="text-left">ProductSuffix</th>
                        <th class="text-left all">ProductDate</th>
                        <th class="text-left">OrderNumber</th>
                        <th class="text-left none">SaleModel</th>
                        <th class="text-left none">SaleSuffix</th>
                        <th class="text-left none">SellinDate</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
</div>
<!--/row-->
@section scripts
{
    <script>
        $(document).ready(function () {
            RefreshTable("#dataTables-1");
        });

        function confirmSaleOut(shopcode, shopcell, edino, serialno, model, suffix, selloutdate, sellindate, usercell, userconfirm) {
            var confirmText = '<strong>Shop code:</strong>' + shopcode + ' <strong>Shop cell#:</strong>' + shopcell + '<br/>'
                            + '<strong>Serial number:</strong>' + serialno + '<br/>'
                            + '<strong>Model:</strong>' + model + '<br/>'
                            + '<strong>Confirm comment</strong><br/>'
                            + '<textarea id="cfmCommen" rows="3" class="span8"></textarea>';

            ConfirmDlg('confirm this data...!', confirmText, successFunction = function () {
                var counter = $('#OtpCounter').val();
                var otp = $('#Otp').val();
                var commen = $('#cfmCommen').val();
                var modalData = { ShopCode: shopcode, ShopCell: shopcell, EDINumber: edino, SerialNumber: serialno, Model: model, Suffix: suffix, SelloutDate: selloutdate, SellinDate: sellindate, UserCell: usercell, UserConfirm: userconfirm, ConfirmComment: commen, OtpCounter: counter, Otp: otp };
                $.post('@Authentication.Configuration.SystemConfiguration.ConfirmSaleoutAction/', modalData, function (data) {
                    if (data.IsSuccess) reload();
                    else alert(data.ErrorMessage);
                });
            });
        }

        function buildAjaxSourcUrl() {
            var orgURL = '?serial=' + $('#SerialNumber').val().trim() + '&model=' + $('#Model').val().trim();

            if (orgURL.length > 1) {
                orgURL = '@Url.Action("SerialChasingData")' + orgURL;
            } else {
                orgURL = '@Url.Action("SerialChasingData")';
            }
            return orgURL;
        }

        function RefreshTable(tableId) {
            var urlData = buildAjaxSourcUrl();
            table = $(tableId).dataTable();
            table._fnClearTable(table.oSettings);
            table.fnDestroy();
            table.fnDraw(true);
            var table2 = $(tableId).dataTable({
                "bServerSide": true,
                "bProcessing": true,
                "responsive": true,
                "bAutoWidth": false,
                oLanguage: {
                    sProcessing: "<img src='http://www.arabianbusiness.com/skins/ab.main/gfx/loading_spinner.gif'/>"
                },
                "aLengthMenu": [10, 30, 50, 100],
                "pageLength": 30,
                "sAjaxSource": urlData,
                "fnServerParams": function (aoData) {
                    aoData.push({ "name": "myval", "value": $('#myselect :selected').val() });
                },
                "fnServerData": function (sSource, aoData, fnCallback) {
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
                "sPaginationType": "bootstrap",//"full_numbers",
                "aoColumns": [
                           { "sName": "SerialNumber", "bSortable": false },//0
                           { "sName": "BoxNo", "bSortable": false },//1
                           { "sName": "ProductModel", "bSortable": false },//2
                           { "sName": "ProductSuffix", "bSortable": false },//3
                           { "sName": "ProductDate", "bSortable": false },//4
                           { "sName": "OrderNumber", "bSortable": false },//5
                           { "sName": "SaleModel", "bSortable": false },//6
                           { "sName": "SaleSuffix", "bSortable": false },//7
                           { "sName": "SellinDate", "bSortable": false }],
            });
        }

        $("#btnSearch").click(function () {
            RefreshTable("#dataTables-1");
        });
    </script>
}